<template>
  <div>
    <Modal
      :value="modalState"
      :title="title"
      :loading="loading"
      ok-text="保存"
      @on-ok="handleSubmit"
      @on-cancel="cancel"
      width="60%">
      <Form
        ref="h5Modal"
        :model="row"
        :rules="ruleInline"
        style="width: 100%"
        :label-width="100">
        <FormItem prop="type" label="展示类型：" style="width: 300px">
          <div>h5</div>
        </FormItem>
      </Form>
      <!-- <content-editor></content-editor> -->
    </Modal>
  </div>
</template>
<script>
import {
  mapActions,
  mapState
} from 'vuex'
import ContentEditor from '_c/content-editor'
export default {
  name: 'H5Modal',
  components: {
    ContentEditor
  },
  data () {
    return {
      title: '',
      loading: true,
      ruleInline: {
        // name: [
        //   { required: true, message: '姓名不能为空', trigger: 'blur' }
        // ],
        // tel: [
        //   { required: true, message: '手机号不能为空', trigger: 'blur' }
        // ]
      }
    }
  },
  updated () {
    if (this.row.id && this.row.id !== '') {
      this.title = '编辑H5列表'
    } else {
      this.title = '添加H5列表'
    }
  },
  computed: {
    ...mapState({
      h5List: state => state.h5Content.h5List,
      row: state => state.h5Content.row,
      modalState: state => state.modal.modalState
    })
  },
  methods: {
    ...mapActions(['updateModalState']),
    changeLoading () {
      this.loading = false
      this.$nextTick(() => {
        this.loading = true
      })
    },
    handleSubmit () {
      this.$refs.h5Modal.validate((valid) => {
        if (!valid) {
          return this.changeLoading()
        }
        this.$emit('h5-valid', {
          id: this.row.id,
          type: 0,
          name: '法拉利啦',
          content: 'this is falali',
          img: ''
        })
      })
    },
    cancel () {
      this.updateModalState(false)
      this.$refs['h5Modal'].resetFields()
    }
  }
}
</script>
